package com.ts;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ForthActivity extends Activity {
	EditText editText = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.forth);
		editText = (EditText) findViewById(R.id.forthedittext);
		Button buttonOK = (Button) findViewById(R.id.OK);
		buttonOK.setOnClickListener(new ForthButtonClickListener());
		Button cancelButton = (Button) findViewById(R.id.cancel);
		cancelButton.setOnClickListener(new CancelButtonClickListener());
		//		Button button2 = (Button) findViewById(R.id.forthbutton2);
		//此时 这里的 button2 为空 是因为R.layout.forth 中找不到button2空间 所以这里会报错
		//也就是说 使用findViewById(int id) 方法的时候 参数中的id必须在 目前此activtiy使用的
		// layout.xml文件中
		//		button2.setOnClickListener(new Button2ClickListener());
		System.out.println("_____________________OnCreate()______________________");
	}

	private class ForthButtonClickListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			String test = editText.getText().toString();
			Toast.makeText(ForthActivity.this, test, Toast.LENGTH_SHORT).show();
		}
	}

	private class CancelButtonClickListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			jump2VviewV2();
		}
	}

	private void jump2VviewV2() {
		setContentView(R.layout.forthv2);
		Button button2 = (Button) findViewById(R.id.forthbutton2);
		button2.setOnClickListener(new Button2ClickListener());
	}

	private class Button2ClickListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			jump2BaseView();
		}
	}

	private void jump2BaseView() {
		setContentView(R.layout.forth);
		Button buttonOK = (Button) findViewById(R.id.OK);
		buttonOK.setOnClickListener(new ForthButtonClickListener());
		Button cancelButton = (Button) findViewById(R.id.cancel);
		cancelButton.setOnClickListener(new CancelButtonClickListener());
	}

	@Override
	protected void onPause() {
		System.out.println("____________________onPause________________________________");
		super.onPause();
	}

	@Override
	protected void onRestart() {
		System.out.println("____________________onRestart________________________________");
		super.onRestart();
	}

	@Override
	protected void onResume() {
		System.out.println("_____________________onResume_______________________________");
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		System.out.println("______________________onDestroy______________________________");
		super.onDestroy();
	}

	@Override
	protected void onStart() {
		System.out.println("________________________onStart____________________________");
		super.onStart();
	}

	@Override
	protected void onStop() {
		System.out.println("________________________onStop____________________________");
		super.onStop();
	}

}